package com.yzr.util;

import com.rabbitmq.client.*;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class RabbitMqClient {

    public static Connection getConnection() throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("localhost");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/yzr");
        connectionFactory.setUsername("yzr");
        connectionFactory.setPassword("yzr");
        return connectionFactory.newConnection();
    }

    public static void close(Channel channel, Connection connection) throws IOException, TimeoutException {
        if (null != channel) channel.close();
        if (null != connection) connection.close();
    }

}
